<template>
  <div class="front-container">
    <div class="header-nav">
      <div class="header-left-warp">
        <div class="logo-warp">
          <div class="logo">
            <img src="../../../public/logo.svg" alt="" />
          </div>
          <div class="logo-text">{{ projectName }}</div>
        </div>
        <div class="header-navs">
          <el-menu router :default-active="$route.path" class="el-menu-demo" mode="horizontal" @select="handleSelect">
            <el-menu-item index="/front/home">首页</el-menu-item>
          </el-menu>
        </div>
      </div>
      <div class="user-warp">
        <div v-if="!user" class="btn-login">
          <el-button size="medium" type="primary">登录</el-button>
        </div>
        <el-dropdown v-else>
          <div class="user-avatar">
            <img :src="user.avatarUrl" alt="" />
          </div>
          <el-dropdown-menu size="medium" slot="dropdown">
            <el-dropdown-item>{{ user.nickname }}</el-dropdown-item>
            <el-dropdown-item>
              <router-link to="/front/person"><div>个人信息</div></router-link>
            </el-dropdown-item>
            <el-dropdown-item>
              <router-link to="/front/password"><div>修改密码</div></router-link>
            </el-dropdown-item>
            <el-dropdown-item><div @click="logout">退出登录</div></el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
    <div class="main-content">
      <router-view></router-view>
    </div>
  </div>
</template>

<script>
import { projectName } from '../../../config/config.default'
export default {
  name: '',
  data() {
    return {
      projectName: projectName,
      user: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user')) : {}
    }
  },
  methods: {
    handleSelect(key, keyPath) {
      console.log(key, keyPath)
    },
    logout() {
      this.$store.commit('logout')
      this.$message.success('退出成功')
    }
  }
}
</script>

<style lang="scss" scoped>
.front-container {
  background-color: var(--color-background-1);
  min-height: 100vh;
  .header-nav {
    z-index: 10;
    position: sticky;
    top: 0;
    height: 70px;
    background-color: var(--color-background-2);
    // background-color: pink;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    box-shadow: 0 2px 10px 0 rgb(0 0 0 / 10%);
    .header-left-warp {
      display: flex;
      align-items: center;
      .logo-warp {
        display: flex;
        align-items: center;
        .logo {
          width: 30px;
          height: 30px;
          margin-right: 5px;
          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
        }
        .logo-text {
          font-size: 22px;
          font-weight: 500;
          color: var(--color-primary);
        }
      }
      .header-navs {
        margin-left: 50px;
        ::v-deep(.el-menu) {
          background: transparent;
        }
        ::v-deep(.el-menu--horizontal) {
          border: none;
        }
        ::v-deep(.el-menu-item) {
          padding: 0;
          font-size: 17px !important;
          height: 35px;
          margin: 0 10px;
          display: flex;
          align-items: center;
        }
        ::v-deep(.el-submenu__title) {
          padding: 0;
          font-size: 17px !important;
          height: 35px;
          margin: 0 10px;
          display: flex;
          align-items: center;
        }
        ::v-deep(.is-active) {
          border-bottom: 3px solid var(--color-primary);
          color: var(--color-primary);
        }
      }
    }
    .user-warp {
      .user-avatar {
        width: 40px;
        height: 40px;

        border-radius: 50%;
        overflow: hidden;
        border: 1px solid var(--color-primary);
        padding: 2px;
        img {
          width: 100%;
          height: 100%;
          object-fit: cover;
          border-radius: 50%;
        }
      }
    }
  }
}
</style>
